<?php
namespace App\Admin\Controllers\System\Traits;

use App\Wen\Utils\Settings;

trait customTabbarTrait2{
    private function insert_mp_tabbar2($zip){
        $zip->addFromString('custom-tab-bar/index.js', $this->get_mp_tabbar2_js_content());
        $zip->addFromString('custom-tab-bar/index.json', $this->get_mp_tabbar2_json_content());
        $zip->addFromString('custom-tab-bar/index.wxml', $this->get_mp_tabbar2_html_content());
        $zip->addFromString('custom-tab-bar/index.wxss', $this->get_mp_tabbar2_css_content());
    }

    private function get_mp_tabbar2_js_content()
    {
        $uni_tabbar_list = explode(',', Settings::get('uni_tabbar_list', '1,2,3,4,5'));
        if(_empty_($uni_tabbar_list)){
            exit('请先配置tabbar,并提交保存');
        }
        $mp_list  = '';
        for ($i = 0; $i < count($uni_tabbar_list); $i++){
            $dou = ',';
            if($i + 1 == count($uni_tabbar_list)){
                $dou = '';
            }
            $i__ = $i + 1;
            if($uni_tabbar_list[$i] == 1){
                $mp_list .= '
                {
                    pagePath: "/pages/tabbar/index/index",
                    text: "'.Settings::get('uni_tabbar_style_'.$i__.'_text', '').'",
                    iconPath: "/static/tabbar/'.$i__.$i__.'.png",
                    selectedIconPath: "/static/tabbar/'.$i__.'.png",
                }'.$dou;
            }else if($uni_tabbar_list[$i] == 2){
                $mp_list .= '
                {
                    pagePath: "/pages/tabbar/shop/shop",
                    text: "'.Settings::get('uni_tabbar_style_'.$i__.'_text', '').'",
                    iconPath: "/static/tabbar/'.$i__.$i__.'.png",
                    selectedIconPath: "/static/tabbar/'.$i__.'.png",
                }'.$dou;
            }else if($uni_tabbar_list[$i] == 3){
                $mp_list .= '
                {
                    pagePath: "/pages/creat/index/creat",
                    text: "'.Settings::get('uni_tabbar_style_'.$i__.'_text', '').'",
                    iconPath: "/static/tabbar/'.$i__.$i__.'.png",
                    selectedIconPath: "/static/tabbar/'.$i__.'.png",
                    isSpecial: 1,
                    isMidButton: 1,
                }'.$dou;
            }else if($uni_tabbar_list[$i] == 4){
                $mp_list .= '
                {
                    pagePath: "/pages/tabbar/notice/notice",
                    text: "'.Settings::get('uni_tabbar_style_'.$i__.'_text', '').'",
                    iconPath: "/static/tabbar/'.$i__.$i__.'.png",
                    selectedIconPath: "/static/tabbar/'.$i__.'.png",
                }'.$dou;
            }else if($uni_tabbar_list[$i] == 5){
                $mp_list .= '
                {
                    pagePath: "/pages/tabbar/mine/mine",
                    text: "'.Settings::get('uni_tabbar_style_'.$i__.'_text', '').'",
                    iconPath: "/static/tabbar/'.$i__.$i__.'.png",
                    selectedIconPath: "/static/tabbar/'.$i__.'.png",
                }'.$dou;
            }else if($uni_tabbar_list[$i] == 19){
                $mp_list .= '
                {
                    pagePath: "/pages/tabbar/circle/circle",
                    text: "'.Settings::get('uni_tabbar_style_'.$i__.'_text', '').'",
                    iconPath: "/static/tabbar/'.$i__.$i__.'.png",
                    selectedIconPath: "/static/tabbar/'.$i__.'.png",
                }'.$dou;
            }else if($uni_tabbar_list[$i] == 50001){
                $mp_list .= '
                {
                    pagePath: "/pages/tabbar/adopt/adopt",
                    text: "'.Settings::get('uni_tabbar_style_'.$i__.'_text', '').'",
                    iconPath: "/static/tabbar/'.$i__.$i__.'.png",
                    selectedIconPath: "/static/tabbar/'.$i__.'.png",
                }'.$dou;
            }else if($uni_tabbar_list[$i] == 165){
                $mp_list .= '
                {
                    pagePath: "/pages/tabbar/city/city",
                    text: "'.Settings::get('uni_tabbar_style_'.$i__.'_text', '').'",
                    iconPath: "/static/tabbar/'.$i__.$i__.'.png",
                    selectedIconPath: "/static/tabbar/'.$i__.'.png",
                }'.$dou;
            }else if($uni_tabbar_list[$i] == 157){
                $mp_list .= '
                {
                    pagePath: "/pages/tabbar/bureau/bureau",
                    text: "'.Settings::get('uni_tabbar_style_'.$i__.'_text', '').'",
                    iconPath: "/static/tabbar/'.$i__.$i__.'.png",
                    selectedIconPath: "/static/tabbar/'.$i__.'.png",
                }'.$dou;
            }else if($uni_tabbar_list[$i] == 130){
                $mp_list .= '
                {
                    pagePath: "/pages/tabbar/voter/voter",
                    text: "'.Settings::get('uni_tabbar_style_'.$i__.'_text', '').'",
                    iconPath: "/static/tabbar/'.$i__.$i__.'.png",
                    selectedIconPath: "/static/tabbar/'.$i__.'.png",
                }'.$dou;
            }else if($uni_tabbar_list[$i] == 142){
                $mp_list .= '
                {
                    pagePath: "/pages/tabbar/icons/icons",
                    text: "'.Settings::get('uni_tabbar_style_'.$i__.'_text', '').'",
                    iconPath: "/static/tabbar/'.$i__.$i__.'.png",
                    selectedIconPath: "/static/tabbar/'.$i__.'.png",
                }'.$dou;
            }else if($uni_tabbar_list[$i] == 139){
                $mp_list .= '
                {
                    pagePath: "/pages/tabbar/exhibit/exhibit",
                    text: "'.Settings::get('uni_tabbar_style_'.$i__.'_text', '').'",
                    iconPath: "/static/tabbar/'.$i__.$i__.'.png",
                    selectedIconPath: "/static/tabbar/'.$i__.'.png",
                }'.$dou;
            }else if($uni_tabbar_list[$i] == 131){
                $mp_list .= '
                {
                    pagePath: "/pages/tabbar/schedule/schedule",
                    text: "'.Settings::get('uni_tabbar_style_'.$i__.'_text', '').'",
                    iconPath: "/static/tabbar/'.$i__.$i__.'.png",
                    selectedIconPath: "/static/tabbar/'.$i__.'.png",
                }'.$dou;
            }else if($uni_tabbar_list[$i] == 100){
                $mp_list .= '
                {
                    pagePath: "/pages/tabbar/used/used",
                    text: "'.Settings::get('uni_tabbar_style_'.$i__.'_text', '').'",
                    iconPath: "/static/tabbar/'.$i__.$i__.'.png",
                    selectedIconPath: "/static/tabbar/'.$i__.'.png",
                }'.$dou;
            }else if($uni_tabbar_list[$i] == 50){
                $mp_list .= '
                {
                    pagePath: "/pages/tabbar/circleClass/circleClass",
                    text: "'.Settings::get('uni_tabbar_style_'.$i__.'_text', '').'",
                    iconPath: "/static/tabbar/'.$i__.$i__.'.png",
                    selectedIconPath: "/static/tabbar/'.$i__.'.png",
                }'.$dou;
            }else if($uni_tabbar_list[$i] == 87){
                $mp_list .= '
                {
                    pagePath: "/pages/tabbar/category/category",
                    text: "'.Settings::get('uni_tabbar_style_'.$i__.'_text', '').'",
                    iconPath: "/static/tabbar/'.$i__.$i__.'.png",
                    selectedIconPath: "/static/tabbar/'.$i__.'.png",
                }'.$dou;
            }else if($uni_tabbar_list[$i] == 97){
                $mp_list .= '
                {
                    pagePath: "/pages/tabbar/add/add",
                    text: "'.Settings::get('uni_tabbar_style_'.$i__.'_text', '').'",
                    iconPath: "/static/tabbar/'.$i__.$i__.'.png",
                    selectedIconPath: "/static/tabbar/'.$i__.'.png",
                }'.$dou;
            }
        }

        return '
var app = getApp();

Component({
    data: {
        selected: 0,
        sysMessageCount: 0,
        color: "#949494",
        selectColor: "#333333",
        fontWeight: "bold",
        background: "#ffffff;",
        showPopup: false,
        list: ['.$mp_list.'],
        popupTip: \'\',
        popupStyle: {
			bgcolor: "#ffffff",
			itemBgcolor: "#f5f5f5",
			fontColor: "#000000"
		},
		popup: {
			tip: {
				login:  \'\',
				nologin:  \'\',
			},
			button: {
				first: {
					text1:  \'\',
					text2:  \'\',
					path:  \'\'
				},
				second: {
					icon:  \'\',
					text:  \'\',
					path:  \'\'
				},
				third: {
					icon:  \'\',
					text:  \'\',
					path:  \'\'
				},
				fourth: {
					icon:  \'\',
					text:  \'\',
					path:  \'\'
				}
			},
			hot: {
				title:  \'\',
				desc:  \'\',
				list: []
			}
		}
    },
    attached: function () {},
    methods: {
        miniMoveHandle(){},
        shutPopup: function () {
            app.globalData.$mpTabbar.setData({
                showPopup: false
            });
        },
        navigateTo: function (e) {
			app.globalData.$mpTabbar.setData({
			    showPopup: false
			});
			let url = e.currentTarget.dataset.url;
			wx.navigateTo({
				url,
				fail() {
					if(url == "/pagesA/creat/index/creat"){
						wx.navigateTo({
							url: "/pages/creat/index/creat"
						});
					}
				}
			});
        },
        switchTab: function (e) {
            // 短震动骚操作
            wx.vibrateShort();

            let index = e.currentTarget.dataset.index;
            let url = e.currentTarget.dataset.url;

            if (this.data.list[index].isSpecial) {
                if(app.globalData.popup && app.globalData.popup.tip && app.globalData.popup.tip.login && app.globalData.popup.tip.login.length > 0){
                    if( app.globalData.user_created_at && app.globalData.user_created_at.length > 0 ){
                        var now = new Date();
                        var targetDate = new Date(app.globalData.user_created_at);
                        var timeDiff = now.getTime() - targetDate.getTime();
                        var daysDiff = Math.ceil(timeDiff / (1000 * 60 * 60 * 24));

                        app.globalData.$mpTabbar.setData({
                            popup: app.globalData.popup,
                            showPopup: true,
                            popupTip: app.globalData.popup.tip.login.replace(\'[in_days]\', daysDiff)
                        });
                    }else{
                        app.globalData.$mpTabbar.setData({
                            popup: app.globalData.popup,
                            showPopup: true,
                            popupTip: app.globalData.popup.tip.nologin
                        });
                    }
				}else{
					wx.navigateTo({
						url: "/pages/creat/index/creat"
					})
				}
            } else {
                wx.switchTab({
                    url
                });
            }
        }
    }
});
        ';
    }

    private function get_mp_tabbar2_json_content(){
        return '
{
"component": true
}
        ';
    }

    private function get_mp_tabbar2_html_content()
    {
        return file_get_contents(app_path('Admin/Controllers/System/assets/index2.wxml'));
    }

    private function get_mp_tabbar2_css_content()
    {
        return '
.tab-bar {
    position: fixed;
    z-index: 999999;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    padding-bottom: env(safe-area-inset-bottom);
}

.tab-bar-item {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    position: relative;
}

.tab-bar-item-center {
    width: 132rpx;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.tab-bar-item-image {
    width: 48rpx;
    height: 48rpx;
    position: relative;
    margin: auto;
}

.tab-bar-item-view {
    font-size: 20rpx;
    line-height: 22rpx;
    text-align: center;
}

.tab-bar-public {
    width: 100%;
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tab-bar-public-background {
    width: 56rpx;
    height: 56rpx;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tab-bar-public-icon {
    width: 48rpx;
    height: 48rpx;
}

.tab-bar-badge {
    position: absolute;
	top: 4rpx;
	right: 26rpx;
	width: 43rpx;
	height: 29rpx;
	line-height: 29rpx;
	font-size: 22rpx;
	color: #fff;
	text-align: center;
	border-radius: 15rpx;
	background: #FF5F5C;
	z-index: 9999999;
}

.tabbar-mask {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, .4);
    z-index: 999999999;
    backdrop-filter: blur(5px);
}

.mid-publish-popup {
    padding-bottom: 50rpx;
    position: fixed;
    width: 750rpx;
    height: 950rpx;
    bottom: -950rpx;
    transition: bottom .2s;
    opacity: 0;
    z-index: 9999999999;
    border-radius: 40rpx 40rpx 0 0;
    box-sizing: border-box;
}

.mid-publish-popup.show {
    bottom: 0;
    opacity: 1;
}

.mid-publish-popup .content-wrapper {
    position: relative;
    padding: 50rpx 20rpx 0 20rpx;
    height: 100%;
    border-radius: 40rpx 40rpx 0 0;
    overflow-y: auto;
    box-sizing: border-box;
}

.mid-publish-popup .content-wrapper .title {
    text-align: center;
    font-size: 26rpx;
    line-height: 38rpx;
}

.mid-publish-popup .content-wrapper .push-note-btn-wrapper {
    margin-top: 48rpx;
    height: 110rpx;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 10rpx;
	font-size: 30rpx;
    background: '.Settings::get('uni_color_primary', '#fc3a72').';
    border-radius: 20rpx;
}

.mid-publish-popup .content-wrapper .push-note-btn-wrapper .title {
    font-size: 30rpx;
    color: #FFFFFF;
    line-height: 38rpx;
}

.mid-publish-popup .content-wrapper .push-note-btn-wrapper .sub-title {
    font-size: 24rpx;
    color: #FFFFFF;
    line-height: 38rpx;
}

.mid-publish-popup .content-wrapper .push-row-wrapper {
    display: flex;
    margin-top: 20rpx;
    justify-content: space-between;
    align-items: center;
    gap: 20rpx;
}

.mid-publish-popup .content-wrapper .push-row-wrapper .item-wrapper {
    height: 100rpx;
    flex: 1;
    border-radius: 20rpx;
    display: flex;
    justify-content: center;
    align-items: center;
	font-size: 28rpx;
    gap: 10rpx;
	max-width: 230rpx;
}

.mid-publish-popup .content-wrapper .push-row-wrapper .item-wrapper .item-push-icon {
    width: 50rpx;
    height: 50rpx;
}


.mid-publish-popup .content-wrapper .push-row-wrapper .item-wrapper .title {
    font-size: 26rpx;
    line-height: 30rpx;
}

.mid-publish-popup .content-wrapper .inspiration-rank-wrapper {
    margin-top: 50rpx;
}

.mid-publish-popup .content-wrapper .inspiration-rank-wrapper .title {
    font-size: 26rpx;
    line-height: 30rpx;
    text-align: left;
}

.mid-publish-popup .content-wrapper .inspiration-rank-wrapper .sub-title {
    margin-top: 10rpx;
    font-size: 24rpx;
    line-height: 30rpx;
}

.mid-publish-popup .content-wrapper .inspiration-rank-wrapper .rank-list-wrapper {
    margin-top: 20rpx;
    display: flex;
    flex-direction: column;
    gap: 20rpx;
}

.mid-publish-popup .content-wrapper .inspiration-rank-wrapper .rank-list-wrapper .rank-item-wrapper {
    padding: 20rpx 20rpx;
    display: flex;
    align-items: center;
    gap: 10rpx;
    border-radius: 20rpx;
	font-size: 28rpx;
}

.mid-publish-popup .content-wrapper .inspiration-rank-wrapper .rank-list-wrapper .rank-item-wrapper .right-city {
    margin-left: auto;
    font-size: 26rpx;
    line-height: 26rpx;
}
.mid-publish-popup .content-wrapper .close{
	width: 710rpx;
	text-align: center;
	margin-top: 30rpx;
	position: absolute;
	bottom: 0;
}
.mid-publish-popup .close .push-close-icon {
	width: 100rpx;
	height: 100rpx;
	margin: auto;
	border-radius: 50%;
	text-align: center;
	line-height: 100rpx;
	font-size: 44rpx;
	font-weight: bold;
}

        ';
    }


}
